package com.cskaoyan.config;

import com.cskaoyan.interceptor.CustomHandlerInterceptor1;
import com.cskaoyan.interceptor.CustomHandlerInterceptor2;
import com.cskaoyan.interceptor.CustomHandlerInterceptor3;
import com.cskaoyan.interceptor.CustomHandlerInterceptor4;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author stone
 * @date 2022/07/13 10:07
 */
@EnableWebMvc
@ComponentScan("com.cskaoyan.controller")
public class MvcConfiguration implements WebMvcConfigurer {

    @Autowired
    @Qualifier("customHandlerInterceptor1")
    HandlerInterceptor handlerInterceptor;

    // 配置HandlerInterceptor的方法
    // 书写顺序就是HandlerInterceptor的顺序
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //指定作用范围：addPathPatterns方法
        //registry.addInterceptor(new CustomHandlerInterceptor1()).addPathPatterns("/hello/**");
        registry.addInterceptor(handlerInterceptor).addPathPatterns("/hello/**");
        //默认的作用范围/**
        registry.addInterceptor(new CustomHandlerInterceptor2());
        registry.addInterceptor(new CustomHandlerInterceptor3()).addPathPatterns("/goodbye/**");
        registry.addInterceptor(new CustomHandlerInterceptor4());
    }
}
